<?php
namespace app\model;

use PHPExcel;
use PHPExcel_IOFactory;
use PHPExcel_Style_Alignment;
use PHPExcel_Cell_DataType;

class Recordbase{
    public static function getCondition($system,$config,$themeid,$starttime,$endtime,$id=0){
        global  $_P;
        $condition = "";
        //没有员工的定单
        $nowoker = intval($_P['noworker']);
        if ($nowoker==-1 || $nowoker>0){
            if ($nowoker>0){$starttime=$nowoker;}
            $condition .= Worker::getWorkerListSql(' and (ord.status > 0 || ord.status =-2) and ord.workerid not');
        }

        if (!is_numeric($starttime)) {
            $starttime =  strtotime($starttime);
            $condition.= " and ord.addtime >{$starttime}";
        }else{
            $condition.= " and ord.addtime >'{$starttime}'";
        }

        if (!is_numeric($endtime)) {
            $endtime =  strtotime($endtime);
            $condition.= " and ord.addtime <= {$endtime}";
        }else{
            $condition.= " and ord.addtime <= '{$endtime}'";
        }

        if($_P['op2'] == 'scan'){
            $condition.= " and (ord.pid = '{$id}' or ord.id = '{$id}') ";
        }

        $condition .= " and ord.themeid = '{$themeid}' ";

        $workerid = $_P['workerid'];
        if(!empty($workerid)){
            $condition .= Worker::getWokerid($system,$workerid,' and ord.workerid ');
        }

        if(!empty($_P['zhijie'])){
            $condition.= " and ord.fromuid = '{$workerid}'  ";
        }
        $fromuid = $_P['fromuid'];
        if(!empty($fromuid)){
            $condition.= " and (ord.fromuid = '{$fromuid}' )";
        }

        $qrimgid = $_P['qrimgid'];
        if(!empty($qrimgid)){
            $condition.= " and (ord.qrimgid = '{$qrimgid}' )";
        }

        if(!isset($_P['type'])){
            $type = -1;
        }else{
            $type = intval($_P['type']);
        }

        if(!isset($_P['yukuan'])){
            $yukuan = -1;
        }else{
            $yukuan = intval($_P['yukuan']);
        }

        if($type == 10){
            $condition.= " and ord.isfinish = '0' and ord.xunifinish = '0' and ord.status >0 and ord.tuannum>1";
        }elseif($type == 17){
            $condition.= " and ord.isfinish = '0' and ord.xunifinish = '0' and ord.status >0  and ord.tuannum<=1";
            if ($yukuan<1){
                $condition.= " and ord.type =0 ";
            }
        }elseif($type == 11){
            $condition.= " and (ord.isfinish = '1' or ord.xunifinish = '1') and ord.status >0 ";
        }elseif($type == 12){
            $condition.= " and ord.isfirstbuy = 1 and ord.status >0 ";
        }elseif($type == 27){ //砍价进行中
            $condition.= " and b.status = 2 ";
        }elseif($type == 28){ //砍价完成
            $condition.= " and b.status = 1 ";
        }elseif($type == 29){ //砍价失败
            $condition.= " and b.status = 3 ";
        }elseif($type == 31){ //砍价失败
            $condition.= " and ord.renshu = 0 ";
        }elseif($type == 32){ //砍价失败
            $condition.= " and ord.renshu = 1 ";
        }elseif($type == 33){ //砍价失败
            $condition.= " and ord.renshu = 2 ";
        }elseif($type >= 0){
            $condition.= " and ord.type = '{$type}'  ";
        }

        if($yukuan == 25){
            $condition.= " and ord.type = 8 and ord.status >0 ";
        }elseif($yukuan == 26){
            $bukuan = Fans::getWeiBukuanSql($config,$themeid);
            $condition .= str_replace(['uid', 'mobile'], ['ord.uid', 'ord.mobile'], $bukuan['weibukuan']);;
            $condition.= " and ord.addtime<'{$config['yukuantime']}' and ord.status >0 ";
        }elseif($yukuan == 34) {
            $condition .= " and ord.type != 8 and ord.addtime>='{$config['yukuantime']}' and ord.status >0 ";
        }elseif($yukuan == 35){
            $condition.= " and ord.addtime<'{$config['yukuantime']}' and ord.status >0 ";
        }

        if(!isset($_P['status'])){
            $status = -10;
        }else{
            $status = intval($_P['status']);
        }

        if($status == 21){
            $condition.= " and ord.jiagetype = '{$config['joinname']}'  ";
        }elseif($status == 22){
            $condition.= " and ord.jiagetype = '{$config['joinname2']}'  ";
        }elseif($status == 23){
            $condition.= " and ord.jiagetype = '{$config['joinname3']}'  ";
        }elseif($status == 99){
            $condition.= " and (ord.status = 1 or ord.status = 3) ";
        }elseif($status == -9){
            $condition.= " and ord.type = 0  ";
        }elseif($status >= -5){
            $condition.= " and ord.status = '{$status}'  ";
        }

        if($status != -2 && $_P['op2'] != 'scan' && empty($_P['keyword'])){
            $condition.= " and ord.status <> '-2'  ";
        }

        $keyword = trim($_P['keyword']);
        if(!empty($keyword)){
            if (intval($keyword)>10000 && intval($keyword)<30000) {
                $tempa = intval($keyword)-10000;
                $condition.= " and (ord.pid = '". $tempa . "' or ord.id = '". $tempa. "') ";
            } else {
                $condition.= " and (ord.nickname like '%{$keyword}%' or ord.username like '%{$keyword}%' or ord.mobile like '%{$keyword}%'  or ord.`option` like '%{$keyword}%' or ord.address like '%{$keyword}%' or ord.datetime like '%{$keyword}%' or ord.addinfo like '%{$keyword}%')";
            }
        }

        if(!empty($_P['address'])){
//        $condition.= " and ord.address like '%{$_P['address']}%'";
            $condition.= " and FIND_IN_SET('" . $_P['address'] . "' ,REPLACE(`address`, '|', ','))";
        }
        if(!empty($_P['formtwo'])){
//        $condition.= " and ord.formtwo like '%{$_P['formtwo']}%'";
            $condition.= " and FIND_IN_SET('" . $_P['formtwo'] . "' ,REPLACE(`formtwo`, '|', ','))";
        }

        if(!empty($_P['shops'])){
//        $condition.= " and ord.option like '%{$_P['shops']}%'";
            if ($config['shopstype']!=8){
                $condition.= " and FIND_IN_SET('" . $_P['shops'] . "' ,REPLACE(`option`, '|', ','))";
            }
        }
        //多选分类
        if ($_P['category_pids'] && $config['shopstype']==8){
//            $condition.= " and ord.option like '%{$_P['category_pids']}%'";
            if (strpos($_P['category_pids'],',')!==false){
                $category_pids_arr = explode(',',$_P['category_pids']);

                foreach ($category_pids_arr as $ak => $av){
                    if ($ak==0){
                        $condition.= " and find_in_set(".$av.",`ord.option`)";
                    }else{
                        $condition.= " or find_in_set(".$av.",`ord.option`)";
                    }
                }
            }else{
                $condition.= " and find_in_set(".$_P['category_pids'].",`ord.option`)";
            }

        }
        $tuannum = $_P['tuannum'];
        if (!empty($tuannum)){
            $condition.= " and ord.tuannum in (" . implode(',',$_P['tuannum']) . ")";
        }else{
            $tuannum = array();
        }
        return array(
            'condition'=>$condition,
            'tuannum'=>$tuannum,
            'type'=>$type,
            'status'=>$status,
            'keyword'=>$keyword,
            'yukuan'=>$yukuan,
            'workerid'=>$workerid,
            'fromuid'=>$fromuid,
        );
    }

    public static function btn($themeid,$system,$config,$_P,$condition){
        $form_count_tiaojian = str_replace('ord.','',$condition);
        //去除不统计虚拟订单
        if ($system['softstyle']==5) {
            $tuanzhang = $config['jmbiemingwenzi'];
            $danmai = $config['jmbiemingwenzi2'];
        }else{
            $tuanzhang = '团长';
            $danmai = '单买';
        }
        //范围数组
        $range_array = [
            'gsumall' => ['type' => -1,'name'=>'不限','field' => 'gsumall'],
            //拼团
            'gsum0' => ['type' => 0,'name'=>$tuanzhang,'field' => 'gsum0'],
            'gsum1' => ['type' => 1,'name'=>'团员','field' => 'gsum1'],
            'gsum9' => ['type' => 9,'name'=>$danmai,'field' => 'gsum9'],
            'gsum18' => ['type' => 10,'name'=>'拼团中','field' => 'gsum18,gsum10', 'unit' => '团,人'],
            'gsum19' => ['type' => 11,'name'=>'拼团成功','field' => 'gsum19,gsum11', 'unit' => '团,人'],
            'gsum17' => ['type' => 17,'name'=>'独立团','field' => 'gsum17','unit' => '团'],
            //砍价
            'all' => ['type' => -1,'name'=>'不限','field' => 'all'],
            'process' => ['type' => 27,'name'=>'进行中','field' => 'process'],
            'success' => ['type' => 28,'name'=>'砍价成功','field' => 'success'],
            'outtime'  => ['type' => 29,'name'=>'砍价失败','field' => 'outtime'],
            't20' => ['type' => 20,'name'=>'发起砍价','field' => 't20'],
            't21' => ['type' => 21,'name'=>'随时下单','field' => 't21'],
            't22' => ['type' => 22,'name'=>'底价下单','field' => 't22'],
            't23' => ['type' => 23,'name'=>'原价购买','field' => 't23'],
            't24' => ['type' => 24,'name'=>'抢定套餐','field' => 't24'],
            //霸王枪
            'gsum122' => ['type' => 12,'name'=>'补余款','field' => 'gsum122'],
        ];

        //状态
        $status_array = [
            'orderall' => ['status' => 99,'name'=>'所有订单','field' => 'orderall'],
            'gsum13' => ['status' => 0,'name'=>'未支付','field' => 'gsum13'],
            'gsum12' => ['status' => 1,'name'=>'已支付','field' => 'gsum12'],
            'refundfee'  => ['status' => -1,'name'=>'已退款','field' => 'refundfee'],
        ];
        //预售
        $yushou_array = [
            'gsum35' => ['yukuan' => 35,'name'=>'所有占位','field' => 'gsum35'],
            'gsum25' => ['yukuan' => 25,'name'=>'补余款','field' => 'gsum25'],
            'gsum26' => ['yukuan' => 26,'name'=>'未补余款','field' => 'gsum26'],
            'gsum34' => ['yukuan' => 34,'name'=>'全款支付','field' => 'gsum34'],
        ];

        $status_case_sql = "count(case when status > 0 or status=3 then 1 end) as orderall,
                             count(case when status = 0 then 1 end) as gsum13,
                             count(case when status > 0 and status!=3 then 1 end) as gsum12,
                             count(case when status = -1 then 1 end) as refundfee,";

        $recond_case_sql = '';
        $bargain_sum = array();
        if($system['ruanjian']!=5){
            if ($config['maxcountall']>1 || $config['maxcountall2']>1 || $config['showdanmai']==1){
                $recond_case_sql.= "count(case when status > 0 then 1 end) as gsumall,
                                    count(case when type = 0  and status > 0 then 1 end) as gsum0,
                                    count(case when type = 1  and status > 0 then 1 end) as gsum1,
                                    count(case when type = 9  and status > 0 then 1 end) as gsum9,
                                    count(case when status > 0 and tuannum>1 and isfinish = 0 and xunifinish = 0 then 1 end) as gsum10,
                                    count(case when status > 0 and (isfinish = 1 or xunifinish = 1) then 1 end) as gsum11,
                                    count(case when status > 0 and type = 0 and tuannum<=1 and xunifinish = 0 then 1 end) as gsum17,
                                    count(case when status > 0 and type = 0 and tuannum>1 and isfinish = 0 then 1 end) as gsum18,
                                    count(case when status > 0 and type = 0 and (isfinish = 1 or xunifinish = 1) then 1 end) as gsum19,";
            }

            if ($system['islottery']==1) {
                $recond_case_sql .= "count(case when status > 0 and isfirstbuy = 1 then 1 end) as gsum122,";
            }
            //预售统计
            $status_array['gsum16'] = ['status' => -2,'name'=>'虚拟定单','field' => 'gsum16'];
            $status_case_sql .= "count(case when status = -2 then 1 end) as gsum16,";   //虚拟订单
            //多个拼团价
            if ($config['groupprice2']>0 || $config['groupprice3']>0) {
                $group_name = Record::getGroupName($config);
                $range_array['groupnum1'] = ['type' => 31,'name'=>$group_name[0],'field' => 'groupnum1'];
                $recond_case_sql.= "count(case when status > 0 and renshu = 0 then 1 end) as groupnum1,";
                if ($config['groupprice2']>0) {
                    $range_array['groupnum2'] = ['type' => 32,'name'=>$group_name[1],'field' => 'groupnum2'];
                    $recond_case_sql.= "count(case when status > 0 and renshu = 1 then 1 end) as groupnum2,";
                }
                if ($config['groupprice3']>0){
                    $range_array['groupnum3'] = ['type' => 33,'name'=>$group_name[2],'field' => 'groupnum3'];
                    $recond_case_sql.= "count(case when status > 0 and renshu = 2 then 1 end) as groupnum3,";
                }
            }
        }else{
            $bargain_sum = Bargain::getAdminBargainStatusArr($themeid);
            //砍价
            $recond_case_sql .= " count(case when type = 20  and status > 0 then 1 end) as t20,";
            if($config['bargain_mode']==3){
                $recond_case_sql .= "count(case when type = 21  and status > 0 then 1 end) as t21";
            }
            if($config['bargain_mode']==2 || $config['bargain_mode']==3){
                $recond_case_sql .= "count(case when type = 22  and status > 0 then 1 end) as t22,";
            }
            if($bargain_sum['t23']>0 || $config['bargain_isdirectbuy']==1){
                $recond_case_sql .= "count(case when type = 23  and status > 0 then 1 end) as t23,";
            }
            if($system['bargain_gift']==1){
                $recond_case_sql .= "count(case when type = 24  and status > 0 then 1 end) as t24,";
            }
        }
        //线下订单
        $status_array['gsum15'] = ['status' => 3,'name'=>"线下订单",'field' => 'gsum15'];
        $status_case_sql .= "count(case when status=3 then 1 end) as gsum15,";

        if($system['jiage']>0){
            $status_array['gsum21'] = ['status' => 21,'name'=>"{$config['joinname']}",'field' => 'gsum21'];
            $status_array['gsum22'] = ['status' => 22,'name'=>"{$config['joinname2']}",'field' => 'gsum22'];
            $recond_case_sql .= "count(case when jiagetype='{$config['joinname']}' and status > 0 and status!=3 then 1 end) as gsum21,
                                 count(case when jiagetype='{$config['joinname2']}' and status > 0 and status!=3 then 1 end) as gsum22,";
        }
        if($system['jiage']>1){
            $status_array['gsum23'] = ['status' => 23,'name'=>"{$config['joinname3']}",'field' => 'gsum23'];
            $recond_case_sql .= "count(case when jiagetype='{$config['joinname3']}' and status > 0 and status!=3 then 1 end) as gsum23,";
        }
        //去除最后一个逗号
        $status_case_sql = rtrim($status_case_sql, ',');
        $all_list_status = db_find("SELECT {$status_case_sql} FROM " . tablename(t_record) ." where  themeid = {$themeid}");
        if($recond_case_sql){
            $recond_case_sql = rtrim($recond_case_sql, ',');
            $record_sql = "SELECT {$recond_case_sql} FROM " . tablename(t_record) ." where  themeid = {$themeid}" . $form_count_tiaojian;
            $all_list = db_find($record_sql);
            $all_list = array_merge($all_list_status,$all_list);
        } else{
            $all_list = $all_list_status;
        }

        if($bargain_sum){
            $all_list = array_merge((array)$bargain_sum,(array)$all_list);
        }

        if ($config['yukuan'] > 0 && TIMESTAMP > $config['yukuantime']){
            extract(Fans::getYukuanCount($config,$themeid));
            $all_list['gsum35']  =   $gsum26+$gsum25;
            $all_list['gsum26']  =   $gsum26;
            $all_list['gsum25']  =   $gsum25;
            $all_list['gsum34']  =   $gsum34;
        }

        $range_btn = [];
        $status_btn = [
            ['status' => -10,'name'=>'不限','url_type' => 'status','url_type_value'=>'-10']
        ];
        $yushou_btn = [];

        foreach ($all_list as $key=>$val){
            $array_info = [];
            $array_type = 1;
            if($range_array[$key]){       //范围
                $array_info = $range_array[$key];
            }

            if($status_array[$key]){   //状态
                $array_info = $status_array[$key];
                $array_type = 2;
            }

            if($yushou_array[$key]){
                $array_info = $yushou_array[$key];
                $array_type = 3;
            }

            if($array_info){
                $array_info['url_type'] = key($array_info);;
                $array_info['url_type_value'] = $array_info[key($array_info)];
                if(strstr($array_info['field'], ',')){
                    $values = explode(',',$array_info['field']);
                    if($array_info['unit'] &&strstr($array_info['unit'], ',')){
                        $units =   explode(',',$array_info['unit']);
                        $array_info['num'] = $all_list[$values[0]].$units[0].$all_list[$values[1]].$units[1];
                    }else{
                        $array_info['num'] = $all_list[$values[0]].' '.$all_list[$values[1]];
                    }
                }else{
                    if($array_info['unit']){
                        $array_info['num'] = $val.$array_info['unit'];
                    }else{
                        $array_info['num'] = $val;
                    }
                }
                if($array_type==1){
                    if($array_info['type']==$type){
                        $array_info['select'] = 1;
                    }else{
                        $array_info['select'] = 0;
                    }
                    $range_btn[] = $array_info;
                }elseif($array_type==2){
                    $status_btn[] = $array_info;
                }elseif($array_type==3){
                    $yushou_btn[] = $array_info;
                }
            }
        }

        //统计表单数据
        $tuan_num_info = Fans::getTuanNumInfo($themeid,array('level'=>1),$config,$system);
        foreach ($tuan_num_info as $key => $val){
            $tuan_num_info[$key]['txt'] = $val['tuannum'].'人'.str_replace('组','',$val['total']).'团';
        }


        $form_count_tiaojian = str_replace(" and b.status = 1 ",'',$form_count_tiaojian);
        $form_count_tiaojian = str_replace(" and b.status = 2 ",'',$form_count_tiaojian);
        $form_count_tiaojian = str_replace(" and b.status = 3 ",'',$form_count_tiaojian);
        //更新表单统计数据
        $result = Fans::get_form_count($system,$config,$themeid,$form_count_tiaojian);
        $address_list = $result['options2'];
        $formtwo_list = $result['options3'];
        $shops_lists = $result['options5'];

        $options_btn = [];
        if (!empty($shops_lists)){
            $options_btn['title'] = $config['shops'];
            foreach ($shops_lists as $key => $item) {
                if (!empty($item['name'])){
                    $show_name = $item['name'];
                    $item['name']=preg_replace('#[^\x{4e00}-\x{9fa5}A-Za-z0-9_.,|，\-]#u','',$item['name']);
                    $url_type = 'shops';
                    $url_type_val = $item['name'];
                    $select = 0;
                    if (trim($_P['shops']) == $item['name']){
                        $select = 1;
                    }

                    $options_btn['btn'][] =[
                        'name' => $show_name,
                        'num' =>  $item['value'],
                        'select' => $select,
                        'url_type' => $url_type,
                        'url_type_value' => $url_type_val,
                    ] ;
                }
            }
        }

        $formtwo_btn = [];
        if (!empty($formtwo_list)){
            $formtwo_btn['title'] = $config['formtwo'];
            foreach ($formtwo_list as $key => $item) {
                $show_name = $item['name'];
                $item['name']=preg_replace('#[^\x{4e00}-\x{9fa5}A-Za-z0-9_.,|，\-]#u','',$item['name']);
                $url_type = 'formtwo';
                $url_type_val = $item['name'];
                $select = 0;
                if (trim($_P['formtwo']) == $item['name']){
                    $select = 1;
                }
                $formtwo_btn['btn'][] =[
                    'name' => $show_name,
                    'num' =>  $item['value'],
                    'select' => $select,
                    'url_type' =>  $url_type,
                    'url_type_value' =>  $url_type_val,
                ] ;
            }
        }

        $address_btn = array();
        if (!empty($address_list)){
            $address_btn['title'] = $config['address'];
            foreach ($address_list as $key => $item) {
                $show_name = $item['name'];
                if ($system['is_mystery_boxes']==0 && $system['is_mystery_boxes_feichi']==0){
                    $item['name']=preg_replace('#[^\x{4e00}-\x{9fa5}A-Za-z0-9_.,|，\-]#u','',$item['name']);
                }

                $select = 0;
                if (trim($_P['address']) == $item['name']){
                    $select = 1;
                }

                $url_type = 'address';
                $url_type_val = $item['name'];
                $address_btn['btn'][] =[
                    'name' => $show_name,
                    'num' =>  $item['value'],
                    'select' =>  $select,
                    'url_type' =>  $url_type,
                    'url_type_value' => $url_type_val,
                ];

                if ($config['get_mystery_boxes']>0 && $config['mystery_gift_select']==1) {
                    $select = 0;
                    if (trim($_P['address']) == '选中'.$item['name']){
                        $select = 1;
                    }
                    $url_type = 'address';
                    $url_type_val = '选中'.$item['name'];
                    $address_btn['btn2'][] =[
                        'name' => $url_type_val,
                        'num' =>  $item['select'],
                        'select' => $select,
                        'url_type' =>  $url_type,
                        'url_type_value' => $url_type_val,
                    ];
                }
            }
            if (!empty($address_btn['btn2'])){
                $address_btn['btn'] = array_merge($address_btn['btn'],$address_btn['btn2']);
            }
        }

        //员工
        $wlist = Worker::getworkerlist($system,$themeid);
        return [
            'range_btn' => $range_btn,
            'status_btn' => $status_btn,
            'yushou_btn' => $yushou_btn,
            'tuan_num_info' => $tuan_num_info,
            'options_btn' => $options_btn,
            'formtwo_btn' => $formtwo_btn,
            'address_btn' => $address_btn,
            'wlist' => $wlist,
        ];

    }

    //返回数据
    public static  function  allList($themeid,$system,$config,$_P)
    {
        global $_G;
        $op = $_P['op'];
        $theme = Theme::getThemeById($themeid);
        $condition = "";
        //没有员工的定单
        $nowoker = intval($_P['noworker']);
        if ($nowoker == -1 || $nowoker > 0) {
            if ($nowoker > 0) {
                $starttime = $nowoker;
            }
            $condition .= Worker::getWorkerListSql(' and (ord.status > 0 || ord.status =-2) and ord.workerid not');
        }

        if(isset($_P['starttime'])&&!empty($_P['starttime'])){
            if(!is_numeric($_P['starttime'])){
                $starttime = strtotime($_P['starttime']);
            }
            $condition .= " and ord.addtime > '$starttime'";
        }

        if(isset($_P['endtime'])&&!empty($_P['endtime'])){
            if(!is_numeric($_P['endtime'])){
                $endtime = strtotime($_P['endtime']);
            }
            $condition .= " and ord.addtime <= '$endtime'";
        }

        $worklist = Worker::getworkerlist($system,$themeid);
        $condition .= " and ord.themeid = '{$themeid}' ";
        $workerid = $_P['workerid'];
        if (!empty($workerid)) {
            $condition .= Worker::getWokerid($system, $workerid, ' and ord.workerid ');
        }
        if (!empty($_P['zhijie'])) {
            $condition .= " and ord.fromuid = '{$workerid}'  ";
        }
        $fromuid = $_P['fromuid'];
        if (!empty($fromuid)) {
            $condition .= " and (ord.fromuid = '{$fromuid}' )";
        }

        if (!isset($_P['type'])) {
            $type = -1;
        } else {
            $type = intval($_P['type']);
        }

        if (!isset($_P['yukuan'])) {
            $yukuan = -1;
        } else {
            $yukuan = intval($_P['yukuan']);
        }

        if ($type == 10) {
            $condition .= " and ord.isfinish = '0' and ord.xunifinish = '0' and ord.status >0 and ord.tuannum>1";
        } elseif ($type == 17) {
            $condition .= " and ord.isfinish = '0' and ord.xunifinish = '0' and ord.status >0  and ord.tuannum<=1";
            if ($yukuan < 1) {
                $condition .= " and ord.type =0 ";
            }
        } elseif ($type == 11) {
            $condition .= " and (ord.isfinish = '1' or ord.xunifinish = '1') and ord.status >0 ";
        } elseif ($type == 12) {
            $condition .= " and ord.isfirstbuy = 1 and ord.status >0 ";
        } elseif ($type == 27) { //砍价进行中
            $condition .= " and b.status = 2 ";
        } elseif ($type == 28) { //砍价完成
            $condition .= " and b.status = 1 ";
        } elseif ($type == 29) { //砍价失败
            $condition .= " and b.status = 3 ";
        } elseif ($type == 31) { //砍价失败
            $condition .= " and ord.renshu = 0 ";
        } elseif ($type == 32) { //砍价失败
            $condition .= " and ord.renshu = 1 ";
        } elseif ($type == 33) { //砍价失败
            $condition .= " and ord.renshu = 2 ";
        } elseif ($type >= 0) {
            $condition .= " and ord.type = '{$type}'  ";
        }
        if ($yukuan == 25) {
            $condition .= " and ord.type = 8 and ord.status >0 ";
        } elseif ($yukuan == 26) {
            $bukuan = Fans::getWeiBukuanSql($config,$themeid);
            $condition .= $bukuan['weibukuan'];
            $condition .= " and ord.addtime<'{$config['yukuantime']}' and ord.status >0 ";
        } elseif ($yukuan == 34) {
            $condition .= " and ord.type != 8 and ord.addtime>='{$config['yukuantime']}' and ord.status >0 ";
        } elseif($yukuan == 35){
            $condition .= " and ord.type = 8 ord.addtime<'{$config['yukuantime']}' and ord.status > 0";
        }

        if (!isset($_P['status'])) {
            $status = -10;
        } else {
            $status = intval($_P['status']);
        }

        if ($status == 21) {
            $condition .= " and ord.jiagetype = '{$config['joinname']}'  ";
        } elseif ($status == 22) {
            $condition .= " and ord.jiagetype = '{$config['joinname2']}'  ";
        } elseif ($status == 23) {
            $condition .= " and ord.jiagetype = '{$config['joinname3']}'  ";
        } elseif ($status == 99) {
            $condition .= " and (ord.status = 1 or ord.status = 3) ";
        } elseif ($status == -9) {
            $condition .= " and ord.type = 0  ";
        } elseif ($status >= -5) {
            $condition .= " and ord.status = '{$status}'  ";
        }

        if ($status != -2 && $_P['op2'] != 'scan' && empty($_P['keyword'])) {
            $condition .= " and ord.status <> '-2'  ";
        }

        if ($status == -9) {
            $sorttype = ' ORDER BY ord.tuannum desc,ord.addtime desc ';
        } elseif ($type == 25) {
            $sorttype = ' ORDER BY ord.addtime desc ';
        } elseif ($type > 9) {
            $sorttype = ' ORDER BY ord.pid desc, ord.type asc, ord.addtime asc';
        } elseif (!empty($_P['tuannum'])) {
            $sorttype = ' ORDER BY ord.tuannum ,ord.pid desc, ord.type desc, ord.addtime asc';
        } else {
            $sorttype = ' ORDER BY ord.addtime desc ';
        }

        $keyword = trim($_P['keyword']);
        if (!empty($keyword)) {
            if (intval($keyword) > 10000 && intval($keyword) < 30000) {
                $tempa = intval($keyword) - 10000;
                $condition .= " and (ord.pid = '" . $tempa . "' or ord.id = '" . $tempa . "') ";
            } else {
                $condition .= " and (ord.nickname like '%{$keyword}%' or ord.username like '%{$keyword}%' or ord.mobile like '%{$keyword}%'  or ord.`option` like '%{$keyword}%' or ord.address like '%{$keyword}%' or ord.datetime like '%{$keyword}%' or ord.addinfo like '%{$keyword}%')";
            }
        }

        if (!empty($_P['address'])) {
//        $condition.= " and ord.address like '%{$_P['address']}%'";
            $condition .= " and FIND_IN_SET('" . $_P['address'] . "' ,REPLACE(`address`, '|', ','))";
        }
        if (!empty($_P['formtwo'])) {
//        $condition.= " and ord.formtwo like '%{$_P['formtwo']}%'";
            $condition .= " and FIND_IN_SET('" . $_P['formtwo'] . "' ,REPLACE(`formtwo`, '|', ','))";
        }

        if (!empty($_P['shops'])) {
//        $condition.= " and ord.option like '%{$_P['shops']}%'";
            if ($config['shopstype'] != 8) {
                $condition .= " and FIND_IN_SET('" . $_P['shops'] . "' ,REPLACE(`option`, '|', ','))";
            }
        }
        //多选分类
        if ($_P['category_pids'] && $config['shopstype'] == 8) {
            $condition .= " and ord.option like '%{$_P['category_pids']}%'";
        }
        $tuannum = $_P['tuannum'];
        if (!empty($tuannum)) {
            $condition .= " and ord.tuannum in (" . implode(',', $_P['tuannum']) . ")";
        } else {
            $tuannum = array();
        }

        if ($system['ruanjian'] == 5) {
            $count_sql = "SELECT COUNT(1) FROM " . tablename(t_record) . " as ord  left join " . tablename(t_bargain_entry) . " as b on b.order_id=ord.id ";
        } else {
            $count_sql = " SELECT COUNT(1) FROM " . tablename(t_record) . " as ord ";
        }
        $sql = $count_sql . "WHERE  1=1  {$condition} ORDER BY ord.id desc";
        $total = (int)db_fetchcolumn($sql);
        $total = $total>0?$total:0;

        $pageSize = 3000;
        $export_array = array();
        $export_total = 1;
        $export_total_arr = array();
        if($total>0){
            $export_total = ceil($total / $pageSize);
            for($i=1;$i<=$export_total;$i++){
                $export_array[] = 'export_submit'.$i;
                $export_total_arr[] = $i;
            }
        }else{
            $export_array[] = 'export_submit1';
            $export_total_arr[] = 1;
        }

        $is_export = 0;
        $pageNumber=1;
        foreach ($_P as $k=>$v){
            if(in_array($k,$export_array)){
                $is_export = 1;
                $pageNumber = array_search($k,$export_array)+1;
            }
        }
        if(!empty($theme['jubf']) ){
            $expName = $theme['jubf'];
        }else{
            $expName = $theme['title'];
        }
        if($export_total>1){
            $expName .= ($pageNumber-1)*$pageSize+1 .'-'. $pageNumber*$pageSize.'条';
        }
        if($is_export==1){
            $export_type = isset($_P['export_type'])?$_P['export_type']:0;
            $excel_data = self::exportData($themeid,$system,$config,$condition,$sorttype,$pageNumber,$pageSize);
            $expCellName = $excel_data['header'];
            $list = $excel_data['list'];
            if($export_type==1){
                return  self::exportExcel($expName, $expCellName,$list,$export_type);
            }else{
                self::exportExcel($expName, $expCellName,$list,$export_type);
            }
        }else{
            return [
                'total' => $total,
                'yukuan' => $yukuan,
                'status' =>  $status,
                'keyword' => $keyword,
                'export_num' =>  $pageSize,
                'export_total' =>  $export_total,
                'export_total_arr' => $export_total_arr
            ];
        }
    }

    //导出没有标题的execl
    public static function exportExcel($expName, $expCellName, $expTableData,$exprot_type){
        global $_G;
        
        $expName =  str_replace('+', '%20', urlencode($expName));//文件名称
        $cellNum = count($expCellName);    //横向个数
        $dataNum = count($expTableData);   //纵向个数

        $objPHPExcel = new \PHPExcel();
        $cellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ');
        $expCellValue = array_values($expCellName);
        for ($i = 0; $i < $cellNum; $i++) {
            $objPHPExcel->getActiveSheet(0)->getStyle($cellName[$i])->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); //居中
            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i] . '1', $expCellValue[$i]);
        }

        $expCellArray = array_keys($expCellName);
        for ($i = 0; $i < $dataNum; $i++){
            for ($j = 0; $j < $cellNum; $j++){
                $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j] . ($i + 2), $expTableData[$i][$expCellArray[$j]]);
                $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($cellName[$j] . ($i + 2), $expTableData[$i][$expCellArray[$j]], PHPExcel_Cell_DataType::TYPE_STRING);   //设置显示的类型
            }
        }
//        header('pragma:public');
//        header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $fileName . '.xls"');
//        header("Content-Disposition:attachment;filename=$fileName.xls");
//        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
//        $objWriter->save('php://output');
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        if($exprot_type==1){
            $base_url = $_G['url_scheme'].$_SERVER['HTTP_HOST'];
            $path = '/attachment/excel/';
            $file_path = IA_ROOT.$path;
            if (!is_dir($file_path)) {
                mkdir($file_path);
                chmod($file_path,0777);
            }
            $filename = time().'.xlsx';
            $objWriter->save($file_path.$filename);
            return $base_url.$path.$filename;
        }else{
            header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
            header('Content-Disposition: attachment;charset=utf-8;filename="' . $expName . '.xlsx"');
            header('Cache-Control: max-age=0');
            $objWriter->save('php://output');
            exit();
        }
    }

    public static function deleteExcel($url){
        $start = strrpos($url,'/') + 1;
        //获取截取字符串中的结束位置
        //截取文档名称
        $document_name = substr($url, $start);
        $path = IA_ROOT.'/attachment/excel/';
        unlink($path.$document_name);
    }

    //导出数据
    public static function exportData($themeid,$system,$config,$condition,$sorttype,$ex_page,$export_num){
        if(!$export_num){
            $export_num = 2000;
        }
        $theme = Theme::getThemeById($themeid);
        Theme::CheckTime($system,$theme);

        if($system['mulit_products']==1||$system['softstyle']==109||$system['softstyle']==108){
            $shangjia_sql = " select * from ".tablename(t_shangjia)." where id >0 and state=1 order by displayorder";
            $shangjia_list = db_select($shangjia_sql,array(),'id');
        }

        if ($system['softstyle']==5) {
            $tuanzhang = $config['jmbiemingwenzi'];
            $danmai = $config['jmbiemingwenzi2'];
        }else{
            $tuanzhang = '团长';
            $danmai = '单买';
        }
        $header = array();
        $header['id'] = '定单号';
        if (!empty($system['wxapp'])) {
            $header['uniacid'] = '来自';
        }
        $header['nickname'] = '微信昵称';
        $header['username'] = '姓名';
        $header['mobile'] = '电话';
        $header['fee'] = '金额';
        if ($system['jiage'] > 0) {
            $header['jiagetype'] = $config['duojiagetips'];
        }
        $form_key = ['datetime','address','formtwo','addinfo','shops'];
        $option_header = [];
        $option_array = [];
        $temp_arr = [];
        $config2 =   Theme::getConfig($themeid,true);
        foreach ($form_key as $item){
            for($i=0;$i<=5;$i++){
                $res  = self::getOption($system,$config2,$shangjia_list,$temp_arr,$option_header,$option_array,$item,$i);
                $temp_arr = $res['temp_arr'];
                $option_header = $res['option_header'];
                $option_array = $res['option_array'];
            }
           /* if (!empty($config2[$item])){
                if($item=='shops'){
                    if($config2['shopstype']==8) {
                        $dx_cate = $config2['dx_cate'];
                        $dx_cate = array_filter($dx_cate);
                        foreach ($dx_cate as $k => $val) {
                            $option_header[$item .'0'.'_'.$val['id']] = $val['name'];
                            if($val['list']){
                                $option_info = [];
                                foreach ($val['list'] as $kk => $vv){
                                    if ($vv['sj_id']  && isset($config['form_five_qty_bind_shangjia']) && $config['form_five_qty_bind_shangjia']){
                                        if($system['is_multiple_merchants']) {
                                            $sj_item = $shangjia_list[$vv['sj_id']];
                                            $sj_name = $sj_item['name'];
                                        }else{
                                            $sj_name = $vv['sj_id'];
                                        }
                                    }
                                    $tmp_p_name = $vv['name'];
                                    if ($sj_name){
                                        $tmp_p_name = $sj_name.'-'.$vv['name'];
                                    }
                                    $option_info[$vv['id']] = $tmp_p_name;
                                }
                                $option_array[$item .'0'.'_'.$val['id']] = $option_info;
                            }
                        }
                    }elseif($config2['shopstype']==4||$config2['shopstype']==5){
                        $shops_lists = Record::get_shops_list($config);
                        $shops_lists = array_filter($shops_lists);
                        if (!empty($shops_lists)) {
                            foreach ($shops_lists as $key => $value) {
                                if (!empty($value)) {
                                    $value = preg_replace('#[^\x{4e00}-\x{9fa5}A-Za-z0-9_.,|，\-]#u', '', $value);
                                    $option_header[$item.'0'.'_'.$key]=$value;
                                }
                            }
                        }
                    }else{
                        $temp_arr[0][$item .'0']= $config2[$item];
                    }
                }else{
                    $temp_arr[0][$item .'0']= $config2[$item];
                }
            }
            if (!empty($config2['form2'][$item])){
                $temp_arr[1][$item .'1']= $config2['form2'][$item];
            }
            if (!empty($config2['form3'][$item])){
                $temp_arr[2][$item .'2']= $config2['form3'][$item];
            }
            if (!empty($config2['presale'][$item])){
                $shopstype = $config2['presale']['shopstype'];
                if($item=='shops'){
                    if($shopstype==8) {
                        $dx_cate = $config2['presale']['dx_cate'];
                        $dx_cate = array_filter($dx_cate);
                        foreach ($dx_cate as $k => $val) {
                            $option_header[$item .'3'.'_'.$val['id']] = $val['name'];
                            if($val['list']){
                                $option_info = [];
                                foreach ($val['list'] as $kk => $vv){
                                    if ($vv['sj_id']  && isset($config['form_five_qty_bind_shangjia']) && $config['form_five_qty_bind_shangjia']){
                                        if($system['is_multiple_merchants']) {
                                            $sj_item = $shangjia_list[$vv['sj_id']];
                                            $sj_name = $sj_item['name'];
                                        }else{
                                            $sj_name = $vv['sj_id'];
                                        }
                                    }
                                    $tmp_p_name = $vv['name'];
                                    if ($sj_name){
                                        $tmp_p_name = $sj_name.'-'.$vv['name'];
                                    }
                                    $option_info[$vv['id']] = $tmp_p_name;
                                }
                                $option_array[$item .'3'.'_'.$val['id']] = $option_info;
                            }
                        }
                    }elseif($shopstype==4||$shopstype==5){
                        $shops_lists = $config2['presale']['options'];
                        if (!empty($shops_lists)) {
                            foreach ($shops_lists as $key => $value) {
                                if (!empty($value)) {
                                    $value = preg_replace('#[^\x{4e00}-\x{9fa5}A-Za-z0-9_.,|，\-]#u', '', $value);
                                    $option_header[$item.'3'.'_'.$key]=$value;
                                }
                            }
                        }
                    }else{
                        $temp_arr[3][$item .'3']= $config2['presale'][$item];
                    }
                }else{
                    $temp_arr[3][$item .'3']= $config2['presale'][$item];
                }
            }
            if (!empty($config2['presale']['form2'][$item])){
                $shopstype = $config2['presale']['form2']['shopstype'];
                if($item=='shops'){
                    if($shopstype==8) {
                        $dx_cate = $config2['dx_cate'];
                        $dx_cate = array_filter($dx_cate);
                        foreach ($dx_cate as $k => $val) {
                            $option_header[$item .'4'.'_'.$val['id']] = $val['name'];
                            if($val['list']){
                                $option_info = [];
                                foreach ($val['list'] as $kk => $vv){
                                    if ($vv['sj_id']  && isset($config['form_five_qty_bind_shangjia']) && $config['form_five_qty_bind_shangjia']){
                                        if($system['is_multiple_merchants']) {
                                            $sj_item = $shangjia_list[$vv['sj_id']];
                                            $sj_name = $sj_item['name'];
                                        }else{
                                            $sj_name = $vv['sj_id'];
                                        }
                                    }
                                    $tmp_p_name = $vv['name'];
                                    if ($sj_name){
                                        $tmp_p_name = $sj_name.'-'.$vv['name'];
                                    }
                                    $option_info[$vv['id']] = $tmp_p_name;
                                }
                                $option_array[$item .'4'.'_'.$val['id']] = $option_info;
                            }
                        }
                    }elseif($shopstype==4||$shopstype==5){
                        $shops_lists = $config2['presale']['form2']['options'];
                        if (!empty($shops_lists)) {
                            foreach ($shops_lists as $key => $value) {
                                if (!empty($value)) {
                                    $value = preg_replace('#[^\x{4e00}-\x{9fa5}A-Za-z0-9_.,|，\-]#u', '', $value);
                                    $option_header[$item.'4'.'_'.$key]=$value;
                                }
                            }
                        }
                    }else{
                        $temp_arr[4][$item .'4']= $config2['presale']['form2'][$item];
                    }
                }else{
                    $temp_arr[4][$item .'4']= $config2['presale']['form2'][$item];
                }
            }
            if (!empty($config2['presale']['form3'][$item])){
                $temp_arr[5][$item .'5']= $config2['presale']['form3'][$item];
            }*/
        }

        for($i=0;$i<=5;$i++){
            if (isset($temp_arr[$i])&&!empty($temp_arr[$i])){
                $header = array_merge($header,$temp_arr[$i]);
            }
        }

        if($option_header){
            $header = array_merge($header,$option_header);
        }

        //判断优惠券
        if ($system['yx_coupon']) {
            $header['coupon_name']='优惠券名称';
            $header['diff_price'] = '优惠券减免金额';
        }
        $header['nickname2'] = '推荐';
        $header['status'] = '状态';
        if ($system['ruanjian'] == 5) {
            if ($system['is_multiple_bargain'] == 1) {
                $header['products'] = '商品';
            }
            $header['remain_amount'] = '当前价';
            $header['bargain_friendnum'] = '帮砍人数';
            $header['bargain_status'] = '砍价状态';
            $header['type'] = '类型';
        } elseif ($system['ruanjian'] !== 1) {
            $header['tuanid'] = '团号';
            $header['tuannum'] = '团人数';
            $header['type'] = '身份';
            $header['isfinish'] = '拼团状态';
        }
        //不开启拼团 不显示团人数
        if ($config['maxcountall'] == 0) {
            unset($header['tuannum']);
        }
        if ($config['game_on_off'] == 1) {
            $header['game_current_level'] = '游戏完成关卡';
            $header['game_max_box'] = '获得宝箱';
            if (!empty($config['five_themeid'])) {
                $header['koi_count'] = '中奖次数';
            }
        }
        if ($config['groupprice2'] > 0) {
            $header['gruoptips'] = '类型';
        }
        if ($config['isicon'] > 0) {
            $header['lightsum'] = '点亮数';
        }
        if ($system['fanpai'] == 1) {
            $header['fanpaijihui'] = '剩余抽奖次数';
            $header['fanpaichoujiang'] = '已抽';
        }
        if ($system['qrlist'] == 1) {
            $header['qrimgid'] = '二维码ID';
            $header['qrimg'] = '二维码';
        }
        if ($system['islottery'] == 1) {
            $header['isfirstbuy'] = '霸王抢';
        }
        $header['addtime'] = '时间';
        if ($system['is_multiple_merchants']) {
            $header['companyname'] = '公司';
        }
        //判断九宫格抽奖
        if ($system['lottery'] == 1 && TIMESTAMP > $config['yx_lt_begintime']) {
            $header['jihui_used'] = '已使用抽奖机会';
            $header['jihui_remain'] = '剩余抽奖机会';
            $header['lottery_info'] = '已获取奖品';
        }
        //判断商家多产品核销
        if ($system['mulit_products'] == 1) {
            foreach ($shangjia_list as $k1 => $v1) {
                $key = 'sj_product_' . $v1['id'];
                $val = $v1['name'] . '-产品';
                $header[$key] = $val;
            }
        }
        //判断教培
        if ($system['softstyle'] == 109||$system['softstyle']==108) {
            $header['course_list'] = '选择课程';
            $header['gift_list'] = '获取礼品';
            $header['coupon_list'] = '优惠券';
        }

        $header['teamname'] = '团队';
        $header['workername'] = '员工';
        $header['is_member'] = '来源';
        $header['chongzhi'] = $system['is_member_points'] == 1 ? '会员积分' : '储值卡余额';
        $header['member_beizhu'] = '备注';
        //阶梯团
        if ($config['tuan_tips']){
            $header['step_tuan_gift']='阶梯团礼品';
        }

        $member_from=array('未标记','老客户','新客户','微信转帐','店内付款');
        $statustr = array("未支付", "已支付", "已核销", "线下定单", "已退款", "虚拟定单",'团满团长免单自动退');
        $luckstr = array("否", "是");
        $firstbuystr = array("正常抢购", "霸王抢");
        $bagaintypestr = array("发起砍价", "随时下单", "底价下单", "原价购买", "抢定套餐");
        $bagainstatusstr = array("砍价成功", "砍价中", "砍价失败");
        $typestr = array($tuanzhang, "团员", "团长补余款", "团员补余款", $danmai);
        $groupstr = array("拼团中", "拼团成功", "虚拟成团");
        $group_name = Record::getGroupName($config);
        $field = '';
        $order_filed = ['id','uid','fromuid','nickname','username','mobile','themeid','openid','datetime','address','formtwo','addinfo','option','pid','tuannum','type','fee','status','xunifinish','isfinish','qrimg','qrimgid','addtime','workerid','isrefund','is_member','chongzhi','member_beizhu','renshu'];
        foreach ($order_filed as $k => $of){
            if($k==0){
                $field .= 'ord.'.$of;
            }else{
                $field .= ',ord.'.$of;
            }
        }
        $join = '';
        if($system['ruanjian']==5){
            $field .=',b.be_id,b.status as bargain_status,b.remain_amount,b.products_id as new_pid';
            $join .= " left join " .tablename(t_bargain_entry) ." as b on b.order_id=ord.id ";
        }
        $record_sql = "SELECT {$field} FROM " . tablename ( t_record ) . " as ord 
                       {$join}" ;
        $sql = $record_sql . " WHERE  1=1 {$condition}   {$sorttype} LIMIT " . ($ex_page - 1) * $export_num .','.$export_num;
        $list = db_select($sql);
        if($list) {
            $fans_where = "";
            $all_fans_where = "";
            $uids = array_column($list, 'uid');
            $uids_str = implode(',', $uids);
            $uids_str = rtrim($uids_str, ",");
            $fans_where .= " and uid in ({$uids_str})";
            $fromuids = array_column($list, 'fromuid');
            $all_uids = array_unique(array_filter(array_merge($uids, (array)$fromuids)));
            $all_uids = implode(',', $all_uids);
            $all_uids = rtrim($all_uids, ",");
            $all_fans_where .= " and uid in ({$all_uids})";
            if ($system['lottery'] == 1 && TIMESTAMP > $config['yx_lt_begintime']) {
                $fans_chance_sql = " select uid,count(*) as jihui_used from " . tablename(yx_lt_chance) . " where themeid=$themeid  and chance<0 and type='system' {$fans_where} group by uid ";
                $fans_chance_list = db_select($fans_chance_sql, array(), 'uid');
                $prize_array = db_getall(yx_lt_prize, ['themeid' => $themeid], ['p_id', 'title'], 'p_id');
                $flag_sql = " select  uid,group_concat(p_id) as prod_id  from " . tablename(yx_lt_flag) . "  where themeid=$themeid {$fans_where} group by uid ";
                $flag_list = db_select($flag_sql, array(), 'uid');
                foreach ($fans_chance_list as $key => $val) {
                    $prize_name = '';
                    if ($flag_list[$key]) {
                        $flag = $flag_list[$key];
                        $prod_arr = explode(',', $flag['prod_id']);
                        $count_arr = array_count_values($prod_arr);
                        foreach ($count_arr as $k2 => $v2) {
                            $prod = $prize_array[$k2];
                            if ($prod) {
                                $prize_name .= '[' . $prod['title'] . ']*' . $v2 . ';';
                            }
                        }
                    }
                    $fans_chance_list[$key]['lottery_info'] = $prize_name;
                }
            }
            //粉丝表查询 包括uid和fromuid的数据
            $fans_sql = "SELECT id,uid,nickname,jihui FROM " . tablename(t_fans) . " WHERE themeid = {$themeid} {$all_fans_where}";
            $fans_list = db_select($fans_sql, array(), 'uid');
            //多商家核销
            if ($system['mulit_products'] == 1) {
                $sj_products_array = db_getall(sj_mulit_products_user_flag, ['themeid' => $themeid], ['id', 'name'], 'id');
                $sj_products_user_sql = " select *,concat(order_id,'_',shangjiaid) as orderid_shangjiaid from " . tablename(sj_mulit_products_user_flag) . " where themeid='$themeid'  {$all_fans_where}";
                $sj_products_user_list = db_select($sj_products_user_sql, array(), 'orderid_shangjiaid');
            }
            //优惠券
            if ($system['yx_coupon']) {
                $coupon_user_sql = " select a.order_id,a.coupon_id,a.status,sum(b.price) as price,group_concat(b.name SEPARATOR ';') as coupon_name  from " . tablename(t_yx_coupon_user_flag) . " as a " .
                    " left join " . tablename(t_yx_coupon) . " as b on b.id=a.coupon_id and b.themeid=a.themeid" .
                    " where a.themeid={$themeid} and a.status=2 group by a.order_id";
                $coupon_user_list = db_select($coupon_user_sql, array(), 'order_id');
            }
            //教培
            if ($system['softstyle'] == 109 || $system['softstyle'] == 108) {
                $shangjia_course_array = db_getall(t_shangjia_course, ['themeid' => $themeid], ['id', 'name'], 'id');
                $shangjia_address_user_sql = " SELECT order_id,group_concat(shangjiaid) as shangjiaid,group_concat(course_id) as course_id,group_concat(address) as  address FROM " . tablename(t_shangjia_address_user_course) . "  WHERE themeid={$themeid} GROUP BY order_id";
                $edu_course_lists = db_select($shangjia_address_user_sql, array(), 'order_id');
                //礼品
                $shangjia_gift_array = db_getall(t_shangjia_gift, ['themeid' => $themeid], ['id', 'name'], 'id');
                $edu_gift_sql = " SELECT order_id,group_concat(gift_id) as gift_id   FROM " . tablename(t_shangjia_user_gift) . " WHERE themeid={$themeid} GROUP BY order_id";
                $edu_gift_lists = db_select($edu_gift_sql, array(), 'order_id');
                //优惠券
                $shangjia_coupon_array = db_getall(t_shangjia_coupon, ['themeid' => $themeid], ['id', 'name'], 'id');
                $edu_coupon_sql = " SELECT order_id,group_concat(coupon_id) as coupon_id   FROM " . tablename(t_shangjia_user_gift) . " WHERE themeid={$themeid} GROUP BY order_id";
                $edu_coupon_lists = db_select($edu_coupon_sql, array(), 'order_id');
            }
            //翻牌
            if ($system['fanpai']==1){
                $fanpaichoujiang_sql = "SELECT openid,COUNT(*) AS count  FROM ".tablename(t_fanpaichoujiang)." WHERE themeid = {$themeid} group by openid";
                $fanpaichoujiang_list = db_select($fanpaichoujiang_sql,array(),'openid');
            }
            //类型订单
            if ($config['yukuan'] > 0 && TIMESTAMP > $config['yukuantime']) {
                $type_record_list = db_select ("SELECT uid,count(*) as cnt  FROM " .tablename ( t_record )."  WHERE themeid ='{$themeid}' and type = 0  GROUP BY uid",array(),'uid');
            }
        }
        $worklist = Worker::getworkerlist($system,$themeid);
        if ($config['yukuan'] > 0 && TIMESTAMP > $config['yukuantime']) {
            $userlist = Fans::getWeiBukuanList($config,$themeid);
        }
        $all_form = Theme::get_all_form($system,$themeid);
        foreach ($list as $index => $row) {
            $form = Theme::get_form_by_record($system, $config, $row, $all_form);
            $list[$index]['datetime'.$form['now_config']] = $row['datetime'];
            $list[$index]['address'.$form['now_config']] = $row['address'];
            $list[$index]['addinfo'.$form['now_config']] = $row['addinfo'];
            $list[$index]['formtwo'.$form['now_config']] = $row['formtwo'];
            if (!empty($form['shops']) && ($form['shopstype']==4 || $form['shopstype']==5)){
                $options = "|".$row['option']."|";
                $shops_lists = self::getShops($config2,$form['now_config']);
                if (!empty($shops_lists)) {
                    foreach ($shops_lists as $key => $value) {
                        if (!empty($value)) {
                            $value2 = preg_replace('#[^\x{4e00}-\x{9fa5}A-Za-z0-9_.,|，\-]#u', '', $value);
                            if (strstr($options,"|".$value2."|")!==false){
                                $list[$index]['shops'.$form['now_config'].'_'.$key]=$value;
                            }
                        }
                    }
                }
            }elseif (!empty($form['shops']) && $form['shopstype']==8){             //多选分类导出处理
                $tmp_item_option = [];
                //判断字符中使用什么分割
                if (strstr($list[$index]['option'],",")){
                    $tmp_item_option = explode(",",rtrim($list[$index]['option'],","));
                }
                if (strstr($list[$index]['option'],"|")){
                    $tmp_item_option = explode("|",rtrim($list[$index]['option'],"|"));
                }
                //按照分类进行拆分
                if ($tmp_item_option && is_array($tmp_item_option)) {
                    foreach ($tmp_item_option as $k => $val){
                        foreach ($option_array as $kk => $vv) {
                            if (substr($kk,0,6)=='shops'.$form['now_config']&&$vv[$val]) {
                                if($list[$index][$kk]){
                                    $list[$index][$kk] = $list[$index][$kk].'|'.$vv[$val];
                                }else{
                                    $list[$index][$kk] = $vv[$val];
                                }
                            }
                        }
                    }
                }
            }else{
                $list[$index]['shops'.$form['now_config']] = $row['option'];
            }

            if(!empty($row['fromuid'])){
                $fans_info =  $fans_list[$row['fromuid']];
                if($fans_info){
                    $list[$index]['nickname2'] = $fans_info['nickname'];
                }else{
                    $list[$index]['nickname2'] = '无';
                }
            }

            if($row['workerid']){
                $worker = Worker::getWokerName($system,$themeid,$row['workerid'],$worklist);
                $list[$index]['workername']= $worker['workername'];
                $list[$index]['teamname']= $worker['teamname'];
                $list[$index]['companyname']= $worker['companyname'];
            }

            if ($system['lottery']==1 && TIMESTAMP > $config['yx_lt_begintime']){
                $fans_info =  $fans_list[$row['uid']];
                if($fans_info){
                    $list[$index]['jihui_remain'] = $fans_info['jihui'];
                }
                $chance_info =  $fans_chance_list[$row['uid']];
                if($chance_info){
                    $list[$index]['jihui_used'] = $chance_info['jihui_used'];
                    $list[$index]['lottery_info'] = $chance_info['lottery_info'];
                }
            }

            if ($system['ruanjian']==0 && $system['softstyle']==5 && !empty($row['address'])) {
                $item = db_find ( "SELECT * FROM " . tablename ( t_shengshi ) . " WHERE areaId= '" . $row['address']."'");
                $xianname = $item['areaName'];
                if (!empty($item)){
                    $item = db_find ( "SELECT * FROM " . tablename ( t_shengshi ) . " WHERE areaId= " . $item['parentId']);
                    $shiname = $item['areaName'];
                }
                if (!empty($item)){
                    $item = db_find ( "SELECT * FROM " . tablename ( t_shengshi ) . " WHERE areaId= " . $item['parentId']);
                    $shengname = $item['areaName'];
                }
                $list[$index]['address'] = $shengname . $shiname .$xianname;
            }

//            if ($row['type']==0){
//                $list[$index]['tuanid'] = $row['id']+10000;
//            }else
            if ($row['type']==9){
                $list[$index]['tuanid'] = 0;
            }else{
                $list[$index]['tuanid'] = $row['pid']+10000;
            }

            $list[$index]['is_member'] = $member_from[$list[$index]['is_member']];
            if ($config['groupprice2']>0 && $row['type']!=9) {
                $list[$index]['gruoptips'] =$group_name[$row['renshu']];
            }

            if ($system['wxapp']==$row['uniacid']){
                $list[$index]['uniacid'] = "小程序";
            }else{
                $list[$index]['uniacid'] = "H5";
            }
            $list[$index]['nickname']=str_replace('"',"",$list[$index]['nickname']);
            $list[$index]['nickname']=str_replace(',',"",$list[$index]['nickname']);
            $list[$index]['nickname2']=str_replace('"',"",$list[$index]['nickname2']);
            $list[$index]['nickname2']=str_replace(',',"",$list[$index]['nickname2']);
            $list[$index]['username']=str_replace('"',"",$list[$index]['username']);
            $list[$index]['username']=str_replace(',',"",$list[$index]['username']);
            $list[$index]['beizhu']=str_replace('"',"",$list[$index]['beizhu']);
            $list[$index]['beizhu']=str_replace(',',"，",$list[$index]['beizhu']);
            //商家多产品核销
            if ($system['mulit_products']==1){
                if ($shangjia_list){
                    foreach ($shangjia_list as $k => $v){
                        $orderid_shangjiaid = $row['id'].'_'.$v['id'];
                        // $user_mulit_falg = \SjMulitVerifyModel::getUserSjProductBySjId($themeid,$row['uid'],$row['id'],$v['id']);
                        $user_mulit_falg = $sj_products_user_list[$orderid_shangjiaid];
                        if ($user_mulit_falg){
                            foreach ($user_mulit_falg as $kk => $vv){
                                $item_str = $vv['name'];
                                if ($vv['status']==1){
                                    //未核销
                                    $item_str.='->[未核销]';
                                }elseif ($vv['status']==2){
                                    //已核销
                                    $r = Worker::getWokerName($system,$themeid,$user_mulit_falg['workerid'],$worklist);
                                    $ttmp_workername=$r['workername'];
                                    $ttmp_teamname=$r['teamname'];
                                    $ttmp_companyname=$r['companyname'];
                                    $item_str.='->[由'.$ttmp_companyname.'-'.$ttmp_teamname.'-'.$ttmp_workername.'在'.$vv['updated_at'].'核销]';
                                }
                                $all_tmp_str.=$item_str.'；';
                            }
                        }
                        $tmp_index_key = 'sj_product_'.$v['id'];
                        $list[$index][$tmp_index_key] = $all_tmp_str;
                    }
                }
            }

            //教培判断
            if ($system['softstyle']==109 ||$system['softstyle']==108){
                $edu_course_list = $edu_course_lists[$row['id']];
                $edu_gift_list = $edu_gift_lists[$row['id']];
                $edu_coupon_list = $edu_coupon_lists[$row['id']];
                if ($edu_course_list){
                    $course_id = $edu_course_list['course_id'];
                    $shangjiaid = $edu_course_list['shangjiaid'];
                    $address = $edu_course_list['address'];
                    if(strpos($course_id, ',')){
                        $course_id_array =   explode(',',$course_id);
                        $shangjiaid_array =   explode(',',$shangjiaid);
                        $address_array =   explode(',',$address);

                        $tmp_course_list = '';
                        foreach ($course_id_array as $k1 => $v1){
                            $shangjia_id  = $shangjiaid_array[$k1];
                            $shangjia_info = $shangjia_list[$shangjia_id];
                            $v1['shangjianame']  =  $shangjia_info['name'];
                            $v1['shangjianame'] = trim($v1['shangjianame']," ");
                            $v1['shangjianame'] = preg_replace("/\s|　/","",$v1['shangjianame']);
                            $v1['shangjianame'] = trim($v1['shangjianame'],',');

                            $course_info = $shangjia_course_array[$v1];
                            $v1['name'] = $course_info['name'];
                            $v1['name'] = trim($v1['name']," ");
                            $v1['name'] = preg_replace("/\s|　/","",$v1['name']);
                            $v1['name'] = trim($v1['name'],',');

                            $v1['address'] = $address_array[$k1];
                            $v1['address'] = trim($v1['address']," ");
                            $v1['address'] = preg_replace("/\s|　/","",$v1['address']);
                            $v1['address'] = trim($v1['address'],',');
                            $tmp_course_list .= '['.$v1['shangjianame'].']'.$v1['name'].'('.$v1['address'].');';
                        }

                    }else{

                        $shangjia_info = $shangjia_list[$shangjiaid];
                        $v1['shangjianame']  =  $shangjia_info['name'];
                        $v1['shangjianame'] = trim($v1['shangjianame']," ");
                        $v1['shangjianame'] = preg_replace("/\s|　/","",$v1['shangjianame']);
                        $v1['shangjianame'] = trim($v1['shangjianame'],',');

                        $course_info = $shangjia_course_array[$course_id];
                        $v1['name'] = $course_info['name'];
                        $v1['name'] = trim($v1['name']," ");
                        $v1['name'] = preg_replace("/\s|　/","",$v1['name']);
                        $v1['name'] = trim($v1['name'],',');

                        $v1['address'] = $address;
                        $v1['address'] = trim($v1['address']," ");
                        $v1['address'] = preg_replace("/\s|　/","",$v1['address']);
                        $v1['address'] = trim($v1['address'],',');

                        $tmp_course_list  = '['.$v1['shangjianame'].']'.$v1['name'].'('.$v1['address'].');';
                    }
                    //判断存在课程
                    $list[$index]['course_list'] =$tmp_course_list;
                }

                if ($edu_gift_list){
                    //判断存在礼品
                    $tmp_gift_list = '';
                    $gift_ids = $edu_gift_list['gift_id'];
                    $gift_ids_array =   explode(',',$gift_ids);
                    foreach ($gift_ids_array as $k1 => $v1){
                        $gift_info = $shangjia_gift_array[$v1];
                        $v1['name'] = $gift_info['name'];
                        $v1['name'] = trim($v1['name']," ");
                        $v1['name'] = preg_replace("/\s|　/","",$v1['name']);
                        $v1['name'] = trim($v1['name'],',');
                        $tmp_gift_list .= $v1['name'].';';
                    }

                    $list[$index]['gift_list']  =$tmp_gift_list;
                }

                if ($edu_coupon_list){
                    //判断存在优惠券
                    $tmp_coupon_list = '';

                    $coupon_ids = $edu_coupon_list['coupon_id'];
                    $coupon_ids_array =   explode(',',$coupon_ids);
                    foreach ($coupon_ids_array as $k1 => $v1){
                        $coupon_info = $shangjia_coupon_array[$v1];
                        $v1['name'] = $coupon_info['name'];
                        $v1['name'] = trim($v1['name']," ");
                        $v1['name'] = preg_replace("/\s|　/","",$v1['name']);
                        $v1['name'] = trim($v1['name'],',');
                        $tmp_coupon_list .= $v1['name'].';';
                    }
                    $list[$index]['coupon_list']  =$tmp_coupon_list;
                }
            }
            //todo  手机端导出excel 需要补充优惠券新增字段
            //优惠券判断
            if ($system['yx_coupon']){
                $user_coupon_flag = $coupon_user_list[$row['id']];
                if ($user_coupon_flag){
                    $list[$index]['diff_price'] = $user_coupon_flag['price'];
                    $list[$index]['coupon_name'] = $user_coupon_flag['coupon_name'];
                }else{
                    $list[$index]['diff_price'] = 0;
                    $list[$index]['coupon_name'] = '';
                }
            }

            //阶梯团礼品
            if ($config['tuan_tips']){
                $list[$index]['step_tuan_gift']=Common::formatStepTuanGift($config,$row['tuannum']);
            }

            if ($config['yukuan'] > 0 && TIMESTAMP > $config['yukuantime']) {
                $PayStatusRes = getPayStatus($config,$themeid,$userlist,$row['id'],$row['status'],$row['addtime'],$row['type'],true);
                $list[$index]['status'] = $PayStatusRes['txt'];
                $list[$index]['bukuan'] = $PayStatusRes['bukuan'];
            }

            if ($system['islottery']==1) {
                $list[$index]['isfirstbuy'] = $firstbuystr[$row['isfirstbuy']];
            }
            $list[$index]['id'] = $row['id']+9000;
            if($row['addtime'] > 0){
                $list[$index]['addtime']  = date('Y-m-d H:i:s',$row['addtime']);
            }
            //虚拟成团
            if ($row['xunifinish']==1){
                $row['isfinish'] = 2;
                if ($row['renshu']==1) {
                    $list[$index]['tuannum'] = $config['maxcountall2'];
                }elseif ($row['renshu']==2) {
                    $list[$index]['tuannum'] = $config['maxcountall3'];
                }else {
                    $list[$index]['tuannum'] = $config['maxcountall'];
                }
            }

            if($row['status'] > 0){
                $list[$index]['status'] = $statustr[$row['status']];
                $list[$index]['isfinish'] = $groupstr[$row['isfinish']];
            }elseif( $row['status'] == -1){
                if ($row['isrefund']==5){
                    $list[$index]['status'] = $statustr[6];
                    $list[$index]['isfinish'] = $groupstr[$row['isfinish']];
                }else{
                    $list[$index]['status'] = $statustr[4];
                    $list[$index]['isfinish'] = "";
                }
            }elseif( $row['status'] == -2){
                if ($row['isrefund']==5){
                    $list[$index]['status'] = $statustr[6];
                    $list[$index]['isfinish'] = $groupstr[$row['isfinish']];
                }else{
                    $list[$index]['status'] = $statustr[5];
                    $list[$index]['isfinish'] = $groupstr[$row['isfinish']];
                }
            }else{
                $list[$index]['status'] = $statustr[$row['status']];
                if ($row['status'] == 0) {
                    $list[$index]['isfinish'] = "";
                }else{
                    $list[$index]['isfinish'] = $groupstr[$row['isfinish']];
                }
            }

            if ($system['fanpai']==1){
                $fanpaichoujiang_info = $fanpaichoujiang_list[$row['openid']];
                $yichou = $fanpaichoujiang_info['count'];
                $jihui = $config['fanpailimit'] - $yichou;
                $fans  = $fans_list[$row['uid']];
                $list[$index]['fanpaijihui'] =  ($jihui>$fans['jihui']) ? $fans['jihui'] : $jihui ;
            }

            if($config['isicon'] > 0){
                $list[$index]['lightsum'] =Scan::getlightsum($config,$themeid,$row['openid'],$row['uid']);
            }

            if ($system['ruanjian']==5){
                if ($system['is_multiple_bargain'] == 1){
                    $list[$index]['products'] = $config['bargain_products'][$row['new_pid']-1]['name'];
                }
                if (!empty($row['type'])){
                    $list[$index]['type'] = $bagaintypestr[$row['type']-20];
                }
                if (!empty($row['bargain_status'])) {
                    $list[$index]['bargain_status'] = $bagainstatusstr[$row['bargain_status'] - 1];
                }
                if (!empty($row['be_id'])){
                    $list[$index]['bargain_friendnum']=Bargain::getFriendBargainCountByFromUidAndBeId($themeid,$row['be_id'],$row['uid'],'all');
                }
            }else{
                if ($row['type']==8){
                    $type_record = $type_record_list[$row['uid']];
                    if (!empty($type_record)){
                        $row['type'] = 2;
                    }else{
                        $row['type'] =3;
                    }
                }
                if ($row['type']==9){
                    $row['type']=4;
                }
                $list[$index]['type'] = $typestr[$row['type']];
            }
            if ($config['game_on_off']==1 && !empty($row['uid'])){
                $temp = Game::apiGetUserGameAndBoxInfo($themeid,$row['uid']);
                $list[$index]['game_current_level'] = $temp['current_level'];
                $list[$index]['game_max_box'] = $temp['max_box'];
                if (!empty($config['five_themeid'])){
                    $temp = Koi::apiGetPrizeCount($config['five_themeid'],$row['uid']);;
                    $list[$index]['koi_count'] = $temp['default_count']+$temp['convert_count'];
                }
            }
        }

        return [
            'header' =>  $header,
            'list' => $list
        ];
    }

    static function getlightsum($config,$themeid,$openid,$uid){
        global $_G;
        $lightsum = 0;
        if ($config['isicon']!=3) {
            if($config['isicon'] == 1){
                $lightsum = Share::getNumByThemeIdAndOpenidAndStatus($themeid,$openid,1);
            }else if ($config['isicon'] == 2) {
                $config['friendlist'] = Scan::getNumByThemeIdAndOpenidXCX($themeid, $uid, $config['iconlimituser']);
                $lightsum = count($config['friendlist']);
            } else {
                $lightsum = Scan::getNumByThemeIdAndOpenidAndStatus($themeid, $openid, 1);
            }
            $friendorder = Record::ispay($config, $uid,$themeid);
            if(!empty($friendorder)){
                $lightsum = $lightsum + $config['iconnum_baoming'];
            }
            //若开启了强制获取资料，客户未留资料等于未点亮
            if (Share::get_icon_ziliao($themeid,$config)){
                $lightsum =0;
            }
        }else{
            $friendlistuid =$uid;
            if (!empty($friendlistuid)){
                $friendfans = Fans::getById($friendlistuid,$themeid);
                $lightsum = $friendfans['friendnum'];

            }else{
                $lightsum = 0;
            }
            //报名即可获得星星数
            if ($config['iconnum_baoming']>0){
                $friendorder = Record::ispay($config,$friendlistuid,$themeid);
                if(!empty($friendorder)){
                    $lightsum = $lightsum + $config['iconnum_baoming'];
                }
            }
        }
        if ($lightsum>0){
            $iconnum2 = max(1,$config['iconnum2']);
            $lightsum = intval($lightsum / $iconnum2);
        }

        if ($config['iconlogo']!=1) {
            if($lightsum >= $config['iconnum']){
                $lightsum = $config['iconnum'];
            }
        }else{
            $shoplist = db_select ( "SELECT * FROM " . tablename (t_shangjia) .
                " WHERE  state = 1 and darkicon<>'' order by displayorder" );
            $iconnum = count($shoplist);

            if($lightsum >= $iconnum){
                $lightsum = $iconnum;
            }
        }
        return $lightsum;
    }

    static function getOption($system,$config2,$shangjia_list,$temp_arr,$option_header,$option_array,$item,$key){
        switch ($key){
            case 0:
                $config_info = $config2;
            break;
            case 1:
                $config_info = $config2['form2'];
            break;
            case 2:
                $config_info = $config2['form3'];
            break;
            case 3:
                $config_info = $config2['presale'];
            break;
            case 4:
                $config_info = $config2['presale']['form2'];
            break;
            case 5:
                $config_info = $config2['presale']['form3'];
            break;
        }
        if(!empty($config_info[$item])){
            if($item=='shops'){
                if($config_info['shopstype']==8) {
                    $dx_cate = $config_info['dx_cate'];
                    $dx_cate = array_filter($dx_cate);
                    foreach ($dx_cate as $k => $val) {
                        $option_header[$item .$key.'_'.$val['id']] = $val['name'];
                        if($val['list']){
                            $option_info = [];
                            foreach ($val['list'] as $kk => $vv){
                                if ($vv['sj_id']  && isset($config2['form_five_qty_bind_shangjia']) && $config2['form_five_qty_bind_shangjia']){
                                    if($system['is_multiple_merchants']) {
                                        $sj_item = $shangjia_list[$vv['sj_id']];
                                        $sj_name = $sj_item['name'];
                                    }else{
                                        $sj_name = $vv['sj_id'];
                                    }
                                }
                                $tmp_p_name = $vv['name'];
                                if ($sj_name){
                                    $tmp_p_name = $sj_name.'-'.$vv['name'];
                                }
                                $option_info[$vv['id']] = $tmp_p_name;
                            }
                            $option_array[$item .$key.'_'.$val['id']] = $option_info;
                        }
                    }
                }elseif($config_info['shopstype']==4||$config_info['shopstype']==5){
                    $shops_lists = $config_info['options'];
                    $shops_lists = array_filter($shops_lists);
                    if (!empty($shops_lists)) {
                        foreach ($shops_lists as $key1 => $value) {
                            if (!empty($value)) {
                                $value = preg_replace('#[^\x{4e00}-\x{9fa5}A-Za-z0-9_.,|，\-]#u', '', $value);
                                $option_header[$item.$key.'_'.$key1]=$value;
                            }
                        }
                    }
                }else{
                    $temp_arr[$key][$item .$key]= $config_info[$item];
                }
            }else{
                $temp_arr[$key][$item .$key]= $config_info[$item];
            }
        }
        return [
             'temp_arr' =>  $temp_arr,
             'option_header' =>  $option_header,
             'option_array' =>$option_array
        ];
    }

    static function getShops($config2,$key){
        switch ($key){
            case 0:
                $config_info = $config2;
                break;
            case 1:
                $config_info = $config2['form2'];
                break;
            case 2:
                $config_info = $config2['form3'];
                break;
            case 3:
                $config_info = $config2['presale'];
                break;
            case 4:
                $config_info = $config2['presale']['form2'];
                break;
            case 5:
                $config_info = $config2['presale']['form3'];
                break;
        }

        if($config_info['options']){
            return array_filter($config_info['options']);
        }else{
            return array();
        }
    }
}